Velocity Template Language

1:#set ($var=XXX)
߿µ
Variable reference 
String literal 
Property reference 
Method reference 
Number literal #set ($i=1) 
ArrayList #set ($arr=["yt1","t2"])



2ע:
  ## XXX
  #* xxx
xxxx
xxxxxxxxxxxx*#

References õ
3 Variables 
 "$" ͷһַΪĸcharacter followed by a VTL Identifier.  (a .. z 
or A .. Z).
԰ַݣ
alphabetic (a .. z, A .. Z) 
numeric (0 .. 9) 
hyphen ("-") 
underscore ("_") 

4Properties 
$Identifier.Identifier
$user.name
hashtable userеĵnameֵ.ƣuser.get("name")

5Methods 
object user.getName() = $user.getName()

6Formal Reference Notation 
{}ѱַֿ 


#set ($user="csy"}
${user}name 
csyname


$username
$!username
$$!
Ҳusernameʱ$usernameַ"$username"$!usernameؿַ"" 

˫   
#set ($var="helo")
test"$var" testhello
test'$var' test'$var'
ͨ stringliterals.interpolate=falseıĬϴʽ



#if( $foo ) 
   <strong>Velocity!</strong>
#end
#if($foo)
#elseif()
#else
#end
$fooΪnullΪBooleanfalseִֵ.

߼:== && || !

ѭ#foreach($var in $arrays ) // ϰVector, a Hashtable or an Array
#end
#foreach( $product in $allProducts )
    <li>$product</li>
#end

#foreach( $key in $allProducts.keySet() )
    <li>Key: $key -> Value: $allProducts.get($key)</li>
#end

#foreach( $customer in $customerList )
    <tr><td>$velocityCount</td><td>$customer.Name</td></tr>
#end
velocityCountļж
# Default name of the loop counter
# variable reference.
directive.foreach.counter.name = velocityCount
# Default starting value of the loop
# counter variable reference.
directive.foreach.counter.initial.value = 1


ļ   
 #include( "one.gif","two.txt","three.htm" )
  
 Parseű
#parse("me.vm" )

 #stop ִֹͣв  

Velocimacros ,൱ں ְ֧
#macro( d )
<tr><td></td></tr>
#end
 
#d()

ĺ
#macro( tablerows $color $somelist )
#foreach( $something in $somelist )
    <tr><td bgcolor=$color>$something</td></tr>
#end
#end
 
Range Operator 
#foreach( $foo in [1..5] )
$foo
#end

